﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;
using Common;

namespace Habito.Admini
{
	public partial class Solution : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty(Ticket.UserName) || Session["username"] == null)
			{
				Response.Redirect("Login.aspx");
			}
			Ajax.BLL.SolutionClass solution = new Ajax.BLL.SolutionClass();
			var list = solution.GetModelList("");
			StringBuilder temp = new StringBuilder();
			foreach (var item in list)
			{
				temp.AppendFormat("<option value = '{0}'>{1}</option>", item.ID, item.ClassName);
			}
			ViewState["options"] = temp.ToString();
		}
		protected override void OnInit(EventArgs e)
		{
			if (Request.QueryString["GetAllSolutions"] == "1")
			{
				int classID = int.Parse(Request.QueryString["classID"].Replace("\'", ""));
				Ajax.BLL.Solutions products = new Ajax.BLL.Solutions();
				List<Ajax.Model.Solutions> list = new List<Ajax.Model.Solutions>();
				StringBuilder temp = new StringBuilder();
				if (classID != -1)
				{
					temp.AppendFormat(" classid={0} ", classID);
				}
				list = products.GetModelList(temp.ToString());
				Response.Write(JsonConvert.SerializeObject(list));
				Response.End();
			}

			else if (Request.QueryString["DeleleSolution"] == "1")
			{
				int id = int.Parse(Request.QueryString["id"]);
				Ajax.BLL.Solutions cla = new Ajax.BLL.Solutions();
				Response.Write(cla.Delete(id));
				Response.End();
			}

			else if (Request.QueryString["GetAllSolutions"] == "1")
			{
				int classID = int.Parse(Request.QueryString["classID"]);
				Ajax.BLL.Solutions products = new Ajax.BLL.Solutions();
				List<Ajax.Model.Solutions> list = new List<Ajax.Model.Solutions>();
				StringBuilder temp = new StringBuilder();
				if (classID != -1)
				{
					temp.AppendFormat("   classid={0} ", classID);
				}
				list = products.GetModelList(temp.ToString());

				Response.Write(JsonConvert.SerializeObject(list));
				Response.End();
			}

			base.OnInit(e);
		}
	}
}